# -*- coding: utf-8 -*- 
# @project : 《Atcoder》
# @Author : created by bensonrachel on 2021/9/1
# @File : D - Number of Shortest paths（BFS）.py
# https://atcoder.jp/contests/abc211/tasks/abc211_d

# How many paths are there in which you can get from City 1 to City N as early as possible?
# 问题解释ans：https://stackoverflow.com/questions/15211611/number-of-shortest-paths-in-a-graph#


def re():
    bfs = [1]
    dist = [None] * (n + 1)
    dist[1] = 0
    cnt = [0] * (n + 1)
    cnt[1] = 1
    #初始化
    for v in bfs:
        for vv in char[v]:
            if (dist[vv] is None):
                dist[vv] = dist[v] + 1
                bfs.append(vv)
                cnt[vv] = cnt[v]
            elif (dist[vv] == dist[v] + 1):#（*）说明有从其他地方到达vv的最短路径和通过v到达vv的最短路径相等，所以路径数目就是加起来
                cnt[vv] += cnt[v]
    return cnt

"""


（*）处解释： 因为用的是BFS，所以dist[vv] > dist[v] + 1 ，这种情况不会出现.
            如果是dist[vv] < dist[v] + 1,这种情况下不需要做任何事，因为这个v到vv的路径不是最短路径，所以不需要更新
"""
if __name__ == "__main__":
    n, m = map(int, input().split())
    char = [[] for _ in range(n + 1)]
    for _ in range(m):
        a, b = map(int, input().split())
        char[a].append(b)
        char[b].append(a)
    res = re()
    print(res[n] % (10 ** 9 + 7))

